package com.clickpaas.workinghours.service.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardDTO;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardDTOPageInfoResponse;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardDTOResponse;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardSaveOrUpdateDataResponseObject;
import com.clickpaas.workinghours.dao.TimeCardDao;
import com.clickpaas.workinghours.entity.TimeCardEntity;
import com.clickpaas.workinghours.service.TimeCardService;
import com.clickpaas.workinghours.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class TimeCardServiceImpl implements TimeCardService {
    @Resource
    private TimeCardDao timeCardDao;

    /**
     * 获取数据
     *
     * @param entity
     * @return
     */
    @Override
    public List<TimeCardDTO> getDataInfo(TimeCardEntity entity) {
        List<TimeCardDTO> reList = new ArrayList<>();
        try {
            if (null == entity || DataInfoUtil.isAllFieldNull(entity)){
                reList = DataInfoUtil.castListCopy(timeCardDao.queryDataInfo(),TimeCardDTOPageInfoResponse.class,TimeCardDTO.class);
            }else {
                reList = DataInfoUtil.castListCopy(timeCardDao.queryDataInfo(entity),TimeCardDTOResponse.class,TimeCardDTO.class);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",entity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 项目数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<TimeCardEntity> DataConver(List<TimeCardDTO> list) {
        return DataInfoUtil.castListCopy(list, TimeCardDTO.class, TimeCardEntity.class);
    }

    /**
     * 工时填报数据入库
     *
     * @param entity
     * @return
     */
    @Override
    public TimeCardSaveOrUpdateDataResponseObject insertDataInfo(TimeCardEntity entity) {
        return timeCardDao.insertDataInfo(entity);
    }

    /**
     * 工时填报数据更新
     *
     * @param query
     * @param update
     * @return
     */
    @Override
    public TimeCardSaveOrUpdateDataResponseObject updateDataInfo(TimeCardEntity query, TimeCardEntity update) {
        return timeCardDao.updateDataInfo(query,update);
    }

    /**
     * 工时填报数据删除
     *
     * @param delete
     * @return
     */
    @Override
    public boolean deleteDataInfo(TimeCardEntity delete) {
        return timeCardDao.deleteDataInfo(delete);
    }

    /**
     * 工时填报主数据查询
     *
     * @return
     */
    @Override
    public Map<Object, Object> getTimeCardMainData(String token) {
        HashMap<Object, Object> fieldMapping = new HashMap<>();
        fieldMapping.put("工时类型", "TimeType");
        String tablename = "TimeCard";
        return DataInfoUtil.getMainData(fieldMapping, tablename,token);
    }
}
